package com.xty.combo;

import com.xty.commodity.Item;
import lombok.extern.slf4j.Slf4j;
import org.assertj.core.util.Lists;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * Created By IntelliJ IDEA
 *
 * @author 许腾洋
 * @date 2021/11/25 description:套餐
 */
@Slf4j
public class Meal {
    public List<Item> items = Lists.newArrayList();

    /**
     * 选食物组合
     */
    public void add(Item item) {
        items.add(item);
    }

    /**
     * 套餐价格
     */
    public float getMealPrice() {
        float sum = 0.0f;
        if (!CollectionUtils.isEmpty(items)) {
            for (Item item : items) {
                if (item != null) {
                    sum += item.price();
                }
            }
        }
        return sum;
    }

    /**
     * 展示详细信息
     */
    public void showItems() {
        if (CollectionUtils.isEmpty(items)) {
            log.info("尚未选择商品");
        }
        for (Item item : items) {
            if (item != null) {
                log.info("foodName:{},packing:{},price:{}", item.foodName(), item.packing().pack(), item.price());
            }
        }
        log.info("当前套餐总价为：{}", getMealPrice());
    }
}
